package jp.eisbahn.mgapi.api.photo;

import java.text.ParseException;
import java.util.Date;

import jp.eisbahn.mgapi.api.Model;
import jp.eisbahn.mgapi.util.DateUtils;

import org.json.simple.JSONObject;

/**
 * This class should be extended sub classes.
 * @author Yoichiro Tanaka
 */
abstract class AbstractModel extends Model {

    /**
     * Initialize this instance.
     * @param newOriginal The JSON object.
     */
    protected AbstractModel(final JSONObject newOriginal) {
        super(newOriginal);
    }

    /**
     * Retrieve the createAt property value.
     * @return The createAt value as Date object.
     * @throws ParseException If the parsing operation is failed.
     */
    public final Date getCreatedAt() throws ParseException {
        String createdAt = getPropertyString("created");
        if (createdAt != null) {
            return DateUtils.convertDate(createdAt);
        } else {
            return null;
        }
    }

    /**
     * Retrieve this ID.
     * @return The ID value.
     */
    public final String getId() {
        return getPropertyString("id");
    }

    /**
     * Retrieve the number of comments.
     * @return The count of comments which this has.
     */
    public final int getNumComments() {
        return getPropertyInt("numComments");
    }

    /**
     * Retrieve the thumbnail image URL.
     * @return The URL string.
     */
    public final String getThumbnailUrl() {
        return getPropertyString("thumbnailUrl");
    }

    /**
     * Retrieve the title.
     * @return The title string.
     */
    public final String getTitle() {
        return getPropertyString("title");
    }

    /**
     * Retrieve the URL.
     * @return The URL string.
     */
    public final String getUrl() {
        return getPropertyString("url");
    }

    /**
     * Retrieve the URL of the view page.
     * @return The URL string.
     */
    public final String getViewPageUrl() {
        return getPropertyString("viewPageUrl");
    }

}
